<?php






    // Author: Tomasz Durka, Akrudo Framework
    // Date: 17th August, 2009
    // Prints out text input tag based on ActiveRecord object
    
    
  
  
  function active_input (ActiveRecord $obj, $attribute, array $params = array()) {
    
    if (get_parent_class($obj) != 'ActiveRecord') {
      Akrudo::raise_warning ('First argument should be ActiveRecord!');
    }
    
    $class_name = get_class($obj);
    $id_add = (!$obj->id || $params['hide_id'] == true) ? '' : "[{$obj->id}]";
    $name = "{$class_name}{$id_add}[{$attribute}]";
    $id = $name;
    $classes[] = strtolower($class_name . '_' . $attribute);
    $generic = '';
    $type = 'text';
    $value = $obj->$attribute;
    
    foreach ($params as $key => $val) {
      switch ($key) {
        case 'hide_value':
          $value = '';
        break;
        case 'class':
          $classes[] = $val;
        break;
        case 'name':
        case 'id':
          $$key = $val;
        break;
        case 'style':
        case 'size':
          $generic .= " {$key}=\"{$val}\"";
        break;
        case 'disabled':
          $generic .= " {$key}=\"{$key}\"";
        break;
        case 'on_change':
          $generic = " onChange=\"{$val}\"";
        break;
        case 'on_click':
          $generic = " onClick=\"{$val}\"";
        break;
        case 'on_focus':
          $generic = " onFocus=\"{$val}\"";
        break;
        case 'on_blur':
          $generic = " onBlur=\"{$val}\"";
        break;
        case 'hidden':
          $type = 'password';
        break;
      }
    }
    $generic .= " onKeyPress=\"if (window.event && window.event.keyCode == 13) blur();\"";
    
    $classes = implode (' ', $classes);
    if ($params['multiline']) {
      $returned = "<textarea name=\"{$name}\" id=\"{$id}\" class=\"{$classes}\"{$generic}>{$value}</textarea><span class=\"active_validation\" style=\"display: none;\></span>";
    } else {
      $returned = "<input type=\"{$type}\" id=\"{$id}\" name=\"{$name}\" value=\"{$value}\" class=\"{$classes}\"{$generic}/><span class=\"active_validation\" style=\"display: none;\"></span>";
    }
    //$returned = htmlspecialchars($returned);
    return $returned;
  }

?>